<template>
  <div class="login">
    <div class="con">
      <h3 class="center">登录</h3>
      <div class="input">
        <el-input v-model="form.username"></el-input>
      </div>
      <div class="input">
        <el-input v-model="form.password"></el-input>
      </div>
      <div class="center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { requserlogin } from "../request/api";
import { successAlert, errorAlert } from "../utils/alert";
export default {
  data() {
    return {
      form: [],
    };
  },
  created() {},
  mounted() {},
  methods: {
    login() {
      requserlogin(this.form).then((res) => {
        if (res.data.code == 200) {
          console.log(res);
          let json = JSON.stringify(res.data.list);
          sessionStorage.setItem("userinfo", json);

          successAlert(res.data.msg);
          console.log(11);
          this.$router.push("/home");
          return;
        }
        if (res.code != 200) {
          errorAlert(res.data.msg);
          return;
        }
      });
    },
  },
};
</script>

<style scoped lang='less'>
@import "../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(@primary, @primary2);
  position: relative;
}
.con {
  width: 300px;
  padding: 30px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 10px;
}
.center {
  text-align: center;
  margin-bottom: 20px;
}
.input {
  margin-bottom: 20px;
}
</style>
